#!coding=utf-8
'''
Created on 2014-4-30

@author: Administrator
'''
#get
#!/usr/bin/env python
import urllib2
import requests
import json
import re
def get():    
    #limit page num  .
    headers = {'content-type': 'application/json'}
    URL = 'http://127.0.0.1:8000/webserver/api/v1/user/?format=json'
#     URL='http://mp.weixin.qq.com/s?__biz=MzI0OTExMDA4OA==&mid=2649658097&idx=1&sn=0ca0cba7ec97df10e07576dcd84039d3&scene=0#wechat_redirect';
#     URL = 'http://127.0.0.1:8000/webserver/api/v1/orderitem/?format=json'
    response = requests.get(URL,headers=headers)
    print response.content  
#     print response.content
# print "get"
# get()
# pattern = re.compile(r'hello')
# match = pattern.match('hello world!')
# if match:
#     print match.group()
#post
#!/usr/bin/env python
# -*- coding:utf-8 -*-
def post():    
#     URL = 'http://127.0.0.1:8000/webserver/api/v1/catagory/' 
#     values = {'id':'4','name':'tc','postion':'4','shop_id':'1','desc':'saysomething'}
    headers = {'content-type': 'application/json'}
    url = 'http://127.0.0.1:8000/webserver/api/v1/user/'
    data = {'openid':'YYYYYYYYYYYYYYYYYYYYY','nickname':'CCCCCCCCCCCCCCCCC','sex':'1','address':'saysomething','score':100,'balance':1000}
    response = requests.post(url, data=json.dumps(data), headers=headers)
    print response.content
# print "post"
# print post()
def postcont():    
#     URL = 'http://127.0.0.1:8000/webserver/api/v1/catagory/' 
#     values = {'id':'4','name':'tc','postion':'4','shop_id':'1','desc':'saysomething'}
    headers = {'content-type': 'application/json'}
    url = 'http://127.0.0.1:8000/webserver/api/v1/user/'
    data = {'openid':'YYYYYYYYYYYYYYYYYYYYY','nickname':'CCCCCCCCCCCCCCCCC','sex':'1','address':'saysomething','score':100,'balance':1000}
    response = requests.post(url, data=json.dumps(data), headers=headers)
    print response.content
#PUT
def put():
    headers = {'content-type': 'application/json'}
    url = 'http://127.0.0.1:8000/webserver/api/v1/user/2/'
    data = {'code':'微信code','name':'姓名','education':'教育','sex':'性别','birthday':'生日','telephone':'手机','marriage':'0','country':'国家','passportno':'护照','idcardno':'身份证','address':'住址','province':'省份','city':'城市','entries':'参赛项目','agerange':'0','experience':'参赛经验','reason':'参赛原因','talenttype':'才艺类型','infosource':'信息来源','contestant':'建议活动增加内容','lovestar':'喜欢的明星','followstar':'希望的学习导师','whichstarmeet':'希望的明星见面会','identity':'除了选手，还希望自己是','gift':'最想得到的礼物','touring':'希望去到的城市'}
    response = requests.put(url, data=json.dumps(data), headers=headers)
    return response.content
# print "put"
# print put()


#delete

def delete():
    request = urllib2.Request("")
    request.get_method = lambda: 'DELETE'
    response = urllib2.urlopen(request)
    
    